#!/usr/bin/ruby
# -*- ruby -*-
#
# http://codeforces.com/problemset/problem/400/C

require 'pp'

class Candy
  attr_accessor :c, :i, :j

  def initialize(c, i, j)
    self.c = c
    self.i = i
    self.j = j
  end
end

def new_matrix(n, m)
  matrix = Array.new(n)
  
  n.times do |i|
    matrix[i] = Array.new(m)
  end

  return matrix
end

def matrix_to_s(matrix)
  rows = []

  matrix.size.times do |i|
    cols = []
    matrix[i].size.times do |j|
      cols << matrix[i][j].c.to_s
    end

    rows << "[" + cols.join(", ") + "]"
  end

  return rows.join("\n")
end

def clockwise(matrix)
  clockwise_matrix = new_matrix(matrix.first.size, matrix.size)

  new_i = 0
  new_j = 0

  (0).upto(matrix.first.size - 1).each do |j|
    (matrix.size - 1).downto(0).each do |i|
      clockwise_matrix[new_i][new_j] = matrix[i][j]
      clockwise_matrix[new_i][new_j].i = new_i
      clockwise_matrix[new_i][new_j].j = new_j

      new_j += 1
    end

    new_i += 1
    new_j = 0
  end

  return clockwise_matrix
end

def horizontal(matrix)
  mirror_matrix = new_matrix(matrix.size, matrix.first.size)

  new_i = 0
  new_j = 0

  (0).upto(matrix.size - 1).each do |i|
    (matrix.first.size - 1).downto(0).each do |j|
      mirror_matrix[new_i][new_j] = matrix[i][j]
      mirror_matrix[new_i][new_j].i = new_i
      mirror_matrix[new_i][new_j].j = new_j

      new_j += 1
    end

    new_i += 1
    new_j = 0
  end

  return mirror_matrix
end

def counter_clockwise(matrix)
  counter_clockwise_matrix = new_matrix(matrix.first.size, matrix.size)

  new_i = 0
  new_j = 0

  (matrix.first.size - 1).downto(0) do |j|
    (0).upto(matrix.size - 1) do |i|
      counter_clockwise_matrix[new_i][new_j] = matrix[i][j]
      counter_clockwise_matrix[new_i][new_j].i = new_i
      counter_clockwise_matrix[new_i][new_j].j = new_j

      new_j += 1
    end

    new_i += 1
    new_j = 0
  end

  return counter_clockwise_matrix
end

def init_matrix(n, m, candies)
  matrix = new_matrix(n, m)

  candies.each do |candy|
    matrix[candy.i][candy.j] = candy 
  end

  return matrix
end

n = m = x = y = z = p = nil

candies = []

ARGF.each_with_index do |line, index|
  next if line.strip.empty?

  if n.nil?
    n, m, x, y, z, p = line.strip.split(' ').map(&:to_i)
  else
    x_k, y_k = line.strip.split(' ').map(&:to_i)

    candies << Candy.new(index - 1, x_k - 1, y_k - 1)
  end
end

matrix = init_matrix(n, m, candies)

x.times do
  matrix = clockwise(matrix)
end

y.times do
  matrix = horizontal(matrix)
end

z.times do
  matrix = counter_clockwise(matrix)
end

candies.each do |candy|
  puts "#{candy.i + 1} #{candy.j + 1}"
end
